package io.gitee.chearnee.fw.dingtalk.msg;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.FieldDefaults;
import org.slf4j.helpers.FormattingTuple;
import org.slf4j.helpers.MessageFormatter;

import java.time.LocalDateTime;

/**
 * @author cn
 * @version 1.0
 * @description
 * @date 2021/12/11 17:06
 */
@Getter
@Setter
@ToString
@FieldDefaults(level = AccessLevel.PRIVATE)
public abstract class DingTalkBaseMessage {

    /**
     * 标题
     */
    String title = "无";
    /**
     * 追踪序列
     */
    String traceId = "无";

    /**
     * 推送业务数据
     */
    String bizData = "无";
    /**
     * 异常信息
     */
    String errorData = "无";

  /**
   * 解决方案
   */
  String solutionAction = "无";

  /**
   * 异常堆栈
   */
  String errorStack = "无";

  /**
   * 发生时间
   */
  LocalDateTime happenedTime = LocalDateTime.now();

  public void setErrorData(String errorData, Object... params) {
    FormattingTuple formattingTuple = MessageFormatter.arrayFormat(errorData, params);
    this.errorData = formattingTuple.getMessage();
  }

  public void setBizData(String bizData, Object... params) {
    FormattingTuple formattingTuple = MessageFormatter.arrayFormat(bizData, params);
    this.bizData = formattingTuple.getMessage();
  }

  public abstract String toMessage();
}
